//
//  ViewController.m
//  UI_24_NSLayoutConstraint
//
//  Created by 李劲成 on 16/4/12.
//  Copyright © 2016年 ljc. All rights reserved.
//

#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createView];
    // Do any additional setup after loading the view, typically from a nib.
}

#pragma mark - 知识点1:NSLayoutContraint 原生约束类.
- (void)createView {
    UIView *viewOfRed = [[UIView alloc]init];
    viewOfRed.backgroundColor = [UIColor redColor];
    viewOfRed.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:viewOfRed];
    [self.view addConstraints:
  @[
        // ViewOfRed 约束 Top
    
    [NSLayoutConstraint constraintWithItem:viewOfRed attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:100],
        // ViewOfRed 约束 Left
    [NSLayoutConstraint constraintWithItem:viewOfRed attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1.0 constant:20],
     // ViewOfRed 约束 Right
    [NSLayoutConstraint constraintWithItem:viewOfRed attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant: - 20],
    // ViewOfRed 约束 高度
    [NSLayoutConstraint constraintWithItem:viewOfRed attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:40]]];
    
    // Masonry 实现约束
    UIView *viewOfGreen = [[UIView alloc]init];
    viewOfGreen.backgroundColor = [UIColor greenColor];
    [self.view addSubview:viewOfGreen];
    
    [viewOfGreen mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewOfRed.mas_bottom).with.offset(20);
        make.left.equalTo(self.view.mas_left).with.offset(20);
        make.height.mas_equalTo(viewOfRed.mas_height);
        make.width.mas_equalTo(viewOfRed.mas_width);
        
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
